package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: GlobalExceptionHandlers
 * Package: com.atguigu.lease.common.exception
 * Description:
 *
 * @Author: tiantian
 * @Create: 2024/10/6 - 22:43
 * @Version: v1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandlers {
    @ExceptionHandler(LeaseException.class)
    @ResponseBody
    public Result leaseExceptionHandler(LeaseException e){
        e.printStackTrace();
        ResultCodeEnum resultCodeEnum = e.getResultCodeEnum();
        return Result.build(null, resultCodeEnum);
    }

    //怕有漏掉的异常
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        e.printStackTrace();
        return Result.fail();
    }
}
